package com.project.aminewsbackend.configuration;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

@Component
public class DateConfig implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS));
        this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS));
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS));
    }
}